www.gusucode.com > VC++ 同学录信息管理系统源代码-源码程序 > VC++ 同学录信息管理系统源代码-源码程序/code/MatesDlg.cpp

    // MatesDlg.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "Mates.h"
#include "MatesDlg.h"

#include "LoginDlg.h"
#include "AboutDialog.h"
#include "DataDlg.h"
#include "UserDlg.h"

#include "mmsystem.h"
#pragma comment(lib,"Winmm.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

static UINT indicators[]=
	{
			IDS_STATUS_DATA,
			ID_INDICATOR_CAPS,
			ID_INDICATOR_CLOCK,
			ID_INDICATOR_NUM,		
			ID_INDICATOR_SCRL,
			IDS_STATUS_SPACE,
	};

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMatesDlg dialog

CMatesDlg::CMatesDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMatesDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMatesDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMatesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMatesDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMatesDlg, CDialog)
	//{{AFX_MSG_MAP(CMatesDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_COMMAND(ID_MENU_RELOGIN, OnMenuRelogin)
	ON_COMMAND(ID_MENU_VERSION, OnMenuVersion)
	ON_COMMAND(ID_MENU_QUIT, OnMenuQuit)
	ON_COMMAND(ID_MENU_NOTEPAD, OnMenuNotepad)
	ON_COMMAND(ID_MENU_CAL, OnMenuCal)
	ON_COMMAND(ID_MENU_SEARCH, OnMenuSearch)
	ON_COMMAND(ID_MENU_HELP, OnMenuHelp)
	ON_COMMAND(ID_MENU_USER, OnMenuUser)
	ON_COMMAND(ID_MENU_MUSIC, OnMenuMusic)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMatesDlg message handlers

BOOL CMatesDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	TBBUTTON button[7];
	int i=0,nStringLength;
	CString string;
	TCHAR *pString;
	m_ImageList.Create(60,56,ILC_COLOR32 | ILC_MASK,0,0);
	m_ToolBar.EnableAutomation();
	m_ToolBar.Create(WS_CHILD |WS_VISIBLE,CRect(0,0,0,0),this,IDR_TOOLBAR);

	for (i=IDI_ICON1;i<=IDI_ICON7;i++)
		m_ImageList.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(i)));
	m_ToolBar.SetImageList(&m_ImageList);
	for (i=0;i<7;i++) {
		button[i].dwData=0;
		button[i].fsState=TBSTATE_ENABLED;
		button[i].fsStyle=TBSTYLE_BUTTON;
		button[i].iBitmap=i;
		string.LoadString(i+IDS_STRING102);
		nStringLength=string.GetLength()+1;
		pString=string.GetBufferSetLength(nStringLength);
		button[i].iString=m_ToolBar.AddStrings(pString);
		string.ReleaseBuffer();
	}
	button[0].idCommand=ID_MENU_RELOGIN;
	button[1].idCommand=ID_MENU_USER;
	button[2].idCommand=ID_MENU_SEARCH;
	button[3].idCommand=ID_MENU_NOTEPAD;
	button[4].idCommand=ID_MENU_CAL;
	button[5].idCommand=ID_MENU_HELP;
	button[6].idCommand=ID_MENU_QUIT;
	m_ToolBar.AddButtons(7,button);
	button[0].fsStyle=TBSTYLE_SEP;
	m_ToolBar.InsertButton(6,&button[0]);
	m_ToolBar.InsertButton(3,&button[0]);
	m_ToolBar.InsertButton(1,&button[0]);
	m_ToolBar.AutoSize;
	m_ToolBar.SetStyle(TBSTYLE_FLAT|CCS_TOP);

	CRect rect;
	GetClientRect(rect);


	m_wndStatusBar.Create(this);
	m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));

	m_wndStatusBar.MoveWindow(0,rect.bottom-20,rect.right,20);
	m_wndStatusBar.SetPaneStyle(2,SBPS_STRETCH);
	SetTimer(1,1000,NULL);
	m_music=1;
	OnMenuMusic();
//	OnMenuRelogin();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMatesDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMatesDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMatesDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMatesDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CTime time;
	time=CTime::GetCurrentTime();
	CString s=time.Format("%H:%M:%S");
	m_wndStatusBar.SetPaneText(2,s);
	CDialog::OnTimer(nIDEvent);
}

void CMatesDlg::OnMenuRelogin() 
{
	// TODO: Add your command handler code here
	CLoginDlg dlg;
	dlg.DoModal();
}

void CMatesDlg::OnMenuVersion() 
{
	// TODO: Add your command handler code here
	CAboutDialog dlg;
	dlg.DoModal();
}

void CMatesDlg::OnMenuQuit() 
{
	// TODO: Add your command handler code here
	mciSendString("close bkMusic",NULL,0,NULL);
	CDialog::OnOK();
}

void CMatesDlg::OnMenuNotepad() 
{
	// TODO: Add your command handler code here
	WinExec("notepad.exe",SW_SHOW);
}

void CMatesDlg::OnMenuCal() 
{
	// TODO: Add your command handler code here
	WinExec("calc.exe",SW_SHOW);
}

void CMatesDlg::OnMenuSearch() 
{
	// TODO: Add your command handler code here
	CDataDlg dlg;
	dlg.DoModal();
}

void CMatesDlg::OnMenuHelp() 
{
	// TODO: Add your command handler code here
	
}

void CMatesDlg::OnMenuUser() 
{
	// TODO: Add your command handler code here
	CUserDlg dlg;
	dlg.DoModal();
}

void CMatesDlg::OnMenuMusic() 
{
	// TODO: Add your command handler code here
	if (m_music) {
	m_music =0;
	HWND hWnd;
	hWnd = GetSafeHwnd();
	char szCmdBuf[300],errBuf[60],szfileName[255];
	MCIERROR mciError;

	strcpy(szfileName,"deskmate.mid"); 

	wsprintf( szCmdBuf,"open %s type sequencer alias bkMusic",szfileName);

	mciError = mciSendString( szCmdBuf, errBuf, sizeof(errBuf), NULL);
	if (mciError == 0)
	{
		mciError = mciSendString("play bkMusic notify",NULL,0, hWnd);

		if (mciError != 0)
			mciSendString("close bkMusic",NULL,0,NULL);
	}
	else
		AfxMessageBox("打开音乐失败");
	}
	else {
		m_music=1;
		mciSendString("close bkMusic",NULL,0,NULL);
	}
}